<?php
/**
 * Created by PhpStorm.
 * User: ouryun
 * Date: 2021/5/17
 * Time: 16:53
 */

namespace app\admin\controller;


use think\admin\Controller;
use think\App;

/**
 * 考勤预警记录管理
 * Class EarlyWarnRecord
 * @package app\admin\controller
 */
class EarlyWarnRecord extends Controller
{
    /**
     * 考勤预警记录表
     * @var string
     */
    protected $table = 'lg_shop_check_work_warning';

    /**
     * 店铺id
     * @var mixed|string
     */
    protected $shop_id = '';

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->shop_id = !empty(session('shop_info.shop_id')) ? session('shop_info.shop_id') : '';
    }

    /**
     * 考勤预警记录列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @auth true
     * @login true
     */
    public function index()
    {
        $this->title = '考勤预警记录列表';
        //数据权限
        $map = $whereMap = [];
        if (!empty($this->shop_id)) {
            $map[] = ['id', 'IN', $this->shop_id];
            $whereMap[] = ['d.id', 'IN', $this->shop_id];
        }
        $this->shopList = $this->app->db->name('lg_distributor')->where($map)->where('status', 1)->field('id,name')->select()->toArray();
        $data = $this->request->param();
        $query = $this->_query($this->table)->alias('ww')
            ->join('lg_distributor d', 'ww.shop_id=d.id', 'LEFT')
            ->field('ww.*,d.name shop_name')
            ->where($whereMap)
            ->order('ww.id DESC');
        if (isset($data['shop_id']) && $data['shop_id'] !== '') {
            $query->where('ww.shop_id', $data['shop_id']);
        }
        if (isset($data['type']) && $data['type'] !== '') {
            $query->where('ww.type', $data['type']);
        }
        if (isset($data['status']) && $data['status'] !== '') {
            $query->where('ww.status', $data['status']);
        }
        $query->page();
    }
}